<?php
namespace Home\Controller;
use Common\Model\CustomerModel;
use Common\Model\CustomerObject;
use Think\Controller;
class IndexController extends Controller {

    /**
     * 主页控制器
     */
    public function index(){
        $this->display('index');
    }

    /**
     * 主页控制器
     */
    public function list_page(){
        /** @var CustomerModel $customerFactory */
        $customerFactory = D('Customer');
        $user = $customerFactory->currentUser();
        $this->assign('user', $user);
        $this->display('list');
    }

    /**
     * 用户登录界面
     */
    public function Login_page(){
        $this->display('login');
    }

    /**
     * 用户登录处理
     */
    public function login_action(){
        /** @var CustomerModel $customerFactory */
        $customerFactory = D('Customer');
        /** @var CustomerObject $customer */
        $customer = $customerFactory->fetchByUsername($_POST['username']);
        if($customer == null)
            $this->error('用户不存在！');
        if(!$customer->checkPassword($_POST['password']))
            $this->error('密码不正确！');
        $customerFactory->login($customer);
        $this->success('登录成功！', '/Index/list_page');
    }

    public function search(){


    }

}